package com.bitjsc.server.data;

import java.util.ArrayList;

public class Card 
{
        // Kieu bai (Ro = R, Co = C, Bich = B, Tep = T )        
        private char type;
        // Gia tri (At = 1, J = 11, Q = 12, K = 13)
        private int value;
        private int isTaked;//la bai co phai la la bai bi an hay ko
                                                // 0: khong phai
                                                // 1: phai

        public int getIsTaked() {
                return isTaked;
        }

        public void setIsTaked(int isTaked) {
                this.isTaked = isTaked;
        }

        public Card(int value, char type)
        {
                this.value = value;
                this.type = type;
                this.isTaked = 0;
        }

        public char getType()
        {
                return type;
        }

        public void setType(char type) throws Exception
        {
                type = Character.toUpperCase(type);
                // Kiem tra kieu bai (R, C, B, T)
                if ((type == 'R') || (type == 'C') || (type == 'B') || (type == 'T'))
                {
                        this.type = type;
                } else
                {
                        throw new Exception("Only support R,C,B,T");
                }
        }

        public int getValue()
        {
                return value;
        }

        public void setValue(int value) throws Exception
        {
                // Kiem tra gia tri bai (At -> K <=> 1 -> 13)
                if ((value < 1) || (value > 13))
                {
                        throw new Exception("1-13");
                } else
                {
                        this.value = value;
                }
        }

        @Override
        public String toString()
        {
                // TODO Auto-generated method stub
                return this.getValue() + "" + this.getType();
        }
        public static Card createCardFromString(String cardName)
        {
                int value = Integer.parseInt(cardName.substring(0, 1));
                char type = (char)Integer.parseInt(cardName.substring(1, 2));
                Card card = new Card(value, type);
                return card;
        }
       
        public static String toStringArrayCard(ArrayList<Card> arrCard, String pattern)
        {
                String str="";
                if(arrCard.size() > 0)
                {
                        for(int i=0; i<arrCard.size(); i++)
                        {
                                str += arrCard.get(i).toString() + pattern;
                        }
                        str = str.substring(0, str.length() - pattern.length());
                }
                return str;
        }
       
        public static String getStringVirtualCard(int cardCount, String pattern)
        {
                String str="";
                if(cardCount > 0)
                {
                        for(int i=0; i<cardCount; i++)
                        {
                                str += "OH" + pattern;
                        }
                        str = str.substring(0, str.length() - pattern.length());
                }
                return str;
        }
       
}

